package cn.itlaobing.Dao;

import cn.itlaobing.Model.UserModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao extends BaseDao {
    public UserModel findByAccount(String account){
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="select * from tbl_user where counts=? or telephone=?";
        UserModel um = null;
        BeanHandler
        try {
            um=qr.query(sql, new ResultSetHandler<UserModel>() {
                public UserModel handle(ResultSet resultSet) throws SQLException {
                    UserModel um=null;
                    if(resultSet.next()){
                        um=new UserModel();
                        um.setAccount(resultSet.getString("counts"));
                        um.setPassowrd(resultSet.getString("pwd"));
                        return um;
                    }
                    return um;
                }
            }, account, account);
            return um;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
